home *** CD-ROM | disk | FTP | other *** search
- Path: rain.fr!news
- From: Claude Leyo <leyo@mail.atlantic-line.fr>
- Newsgroups: comp.lang.c
- Subject: qsort with large files
- Date: Fri, 02 Feb 1996 23:00:28 -0800
- Organization: CSI InterNetNews site
- Message-ID: <3113080C.349E@mail.atlantic-line.fr>
- NNTP-Posting-Host: superman.atlantic-line.fr
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0b5 (Win16; I)
-
- I don't succeed trying to sort a large array of names in a structure
- when the array is >64K. Is there a limitation of qsort() ? Thanks for
- help.
- abstract of the program following:
- struct name_list
- { char name[32];
- } ;
- name_list huge *ptrfirst, huge *ptr;
- int sort_function( name_list huge *p1, name_list huge *p2)
- { return strcmp((( struct name_list *)p1)->name,
- (( struct name_list *)p2)->name);
- }
- int main()
- { int i, nb_entries = 2050L; // problem arises when nb > 2040
- ptrfirst = (name_list *) farcalloc(nb_entries,sizeof(name_list));
- if (ptrfirst==NULL) {printf("not enough main memory"); exit(-1); }
- for (i=0,ptr=ptrfirst; i<nb_entries;i++,ptr++)
- { strcpy(ptr->name," ");
- strset(ptr->name,'a'+random(26)); // generate test data
- }
- qsort((name_list *)ptrfirst,nb_entries,sizeof(name_list),
- (int(*) (const void *, const void *)) sort_function);
- for (i=0,ptr=ptrfirst; i<nb_entries;i++,ptr++)
- printf(" %s \n", ptr->name);
- return 0;
- }
-